#include<stdlib.h>
#include<stdio.h>
#define MAXN 32

int multiply(int a,int b){
    int power[MAXN],i,cnt,c;
    i = c = cnt = 0;
    do{
        if(a&0x0001)
            power[cnt++] = i;
        i++;
        a >>= 1;
    }while(i<31);
    for(i=cnt-1;i>=0;i--)
        c += b << power[i];
    return c;
}

//dividend:a;divider:b;
int division(int a,int b){
    if(b==0 || a < b)
        return 0;
    int res,c,k;
    res = 0;
    while(a>=b){
        for(c=b,k=0;a>=b;k++,c<<=1){
            if(a - c < b){
                break;
            }
        }
        //printf("%d %d %d\n",a,c,k);
        if( a>=c && a-c<b){
            res += 1 << k;
            a -= c;
            break;
        }
        res += 1<<(k-1);
        a -= c>>1;
    }
    return res;
}

int main(){
    printf("%d\n",multiply(20,7));
    printf("%d ",division(20,7));
    return 0;
}
